﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class Logo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Show.Text = "";
        }

        protected void Enter_Click(object sender, EventArgs e)
        {
            var uid = txtUserName.Text.Trim();
            var pwd = txtPassword.Text.Trim();
            var sql = string.Format("select * from UserInfo where UserName ='{0}'", uid);
            var dt = DbHelper.GetData(sql);

            if(dt.Rows.Count == 1)
            {
                var get = dt.Rows[0];
                var IsActive = (bool)get.ItemArray[3];
                var IsDetect = (bool)get.ItemArray[4];
                var Password = get.ItemArray[2].ToString();

                if(IsDetect ==true)
                {
                    Show.Text = "账户已不存在";
                }
                else
                {
                    if(IsActive)
                    {
                        if(pwd==Password)
                        {
                            Response.Redirect("Default.aspx");
                        }
                        else
                        {
                            Show.Text = "账户密码错误";
                        }
                    }
                    else
                    {
                        Show.Text = "账户是否被冻结或者删除";
                    }
                }
            }
            else
            {
                Show.Text = "账户输入错误";
            }
        }

        protected void Riter_Click(object sender, EventArgs e)
        {

            var uid = txtUserName.Text.Trim();
            var pwd = txtPassword.Text.Trim();
            var sql = string.Format("select * from UserInfo where UserName ='{0}'", uid);
            var dt7 = DbHelper.GetData(sql);

            if (dt7.Rows.Count == 0)
            {
                var sql7 = string.Format("insert into UserInfo(UserName,Password)values('{0}','{1}')", uid, pwd);
                DbHelper.AddOr(sql7);
                Show.Text = "账户已注册完成";
            }
            else
            {
                Show.Text = "账户已注册";
            }
        }
    }
}